﻿#ifndef VertexDeclarationCache_t_h
#define VertexDeclarationCache_t_h

#include <Defines.h>
#include <CSharpPropertyMethods.h>

// Riccsson includes.
#include <System/RObject.h>
#include <System/RType.h>

#include <Riccsson/Xna/Framework/Graphics/Vertices/IVertexType.h>
#include <Riccsson/Xna/Framework/Graphics/Vertices/VertexDeclaration.h>

namespace Riccsson
{
	namespace Xna
	{
		namespace Framework
		{
			namespace Graphics
			{
				/// <summary>
				/// Helper class which ensures we only lookup a vertex 
				/// declaration for a particular type once.
				/// </summary>
				/// <typeparam name="T">A vertex structure which implements IVertexType.</typeparam>
				/*internal*/ template<IVertexType T> class VertexDeclarationCache //where T : struct, IVertexType
				{
					private: static GC_PTR<VertexDeclaration> _cached;

					public: static PROP3_GET(GC_PTR<VertexDeclaration>, VertexDeclaration)
					{
						if (_cached == null)
							_cached = VertexDeclaration::FromType(typeof(T));

						return _cached;
					}
				};
			}
		}
	}
}

#endif